package com.example.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
	
//	@Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//       // super.addViewControllers(registry);
//        //浏览器发送 /atguigu 请求来到 success
//		//registry.addViewController("/").setViewName("main");
//        //registry.addViewController("/index.html").setViewName("index");
//        //registry.addViewController("/").setViewName("login");
//    }
	
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new LoginHandlerInterceptor()).
		addPathPatterns("/**").
		//excludePathPatterns("/page/**").
		excludePathPatterns("/login").
		excludePathPatterns("/").
		excludePathPatterns("/static/**").
		excludePathPatterns("/images/**").
		excludePathPatterns("/index.html").
		excludePathPatterns("/login").
		excludePathPatterns("/css").
		excludePathPatterns("/images").
		excludePathPatterns("/js").
		excludePathPatterns("/login.html");
        
	}
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
      //需要告知系统，这是要被当成静态文件的！
        //第一个方法设置访问路径前缀，第二个方法设置资源路径
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/resource/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
 
}
